package com.jxb.e20241230;

public class MajorityElement1_169 {

    public static void main(String[] args) {
        int[] nums = {1,3,3,3,9,4};
        int maxCountNum = findMaxCountNum(nums);
        System.out.println(maxCountNum);
    }

    public static int findMaxCountNum(int[] nums) {
        int currentNum = nums[0];
        int count = 1;
        //从元素1开始
        for (int i = 1;i<nums.length;i++) {
            if (nums[i] == currentNum) {
                count++;
            }else {
                if (count < 1) {
                    currentNum = nums[i];
                    count = 1;
                }else {
                    count--;
                }
            }
        }
        return currentNum;
    }

}
